<template>
    <div class="party_affairs_open_page">

        <div class="note" :style="note">
            <div class="inform">
                <span>党务公开</span>
            </div>
            <div class="tabs">
                <ly-tab v-model="selectedId" :items="items" :options="options" @change="handleChange"></ly-tab>
            </div>
        </div>
        <Loading v-if="notMore" class="empty-text-wrap"/>
        <mu-load-more @load="load" :loading="loading">
             
            <div class="list">
                      
                <div class="bar" v-for="(item,index) in info" :key="index" @click="open_details(item)">
                            
                    <div class="lf">
                        <div class="title">
                            <p>{{item.name}}</p>
                        </div>
                                  <p class="time">{{(item.create_time) | time}}</p>
                    </div>
                    <div class="rf">
                                  <img src="@as/img/dangwu_wode_zp@2x.png" alt="">
                    </div>
                </div>
            </div>
        </mu-load-more>
        <div class="loading" v-if="loadOver" :class="{'notPageOne':p>1||info.length<5}">{{loaded}}</div>
    </div>
</template>

<script>
    import LyTab from "@cp/index";
    import Loading from '@/components/emptyText.vue';

    export default {
        components: {
            LyTab,
            Loading
        },
        data() {
            return {
                p: 1,
                org_type: 1,
                loaded: "加載更多...",
                notMore: false,
                loading: false,
                loadOver: false,
                info: [],
                class_id: 0,
                selectedId: 0,
                bottomSelectedId: 0,
                items: [],
                options: {
                    activeColor: "#333",
                    color: "#999"
                },

                page: 7,
                list: [],
                note: {
                    backgroundImage: "url(" + require("@as/img/dangwu_wode_bj@2x.png") + ")",
                    backgroundRepeat: "no-repeat",
                    backgroundSize: "100% 100%",
                },
            }
        },
        mounted() {
            this.$progress.done();
            this.tabChange();
        },
        methods: {
            open_details: function (item) {
                this.$router.push({path: '../organization/open_details', query: item})
            },
            // 党务公开分类
            async getList() {
                let that = this;
                try {
                    let params = {
                        uid: JSON.parse(Cookies.get('user_71ydj')).id,
                        p: 1,
                        page: that.page,
                        class_id: that.class_id
                    }
                    const url = `/app/moral/index`
                    let res = await that.$http.get(url, params)
                    that.$progress.done()
                    if (res.code === 200) {
                        // debugger

                        that.list = res.data;
                        let index = 0;
                        that.list.moral_class.forEach(function (element) {
                            //动态创建对象的方法将moral_class中的对象push进items中，并将值与对应的固定参数名对应
                            that.items.push({
                                org_type: index++,
                                label: element.name,
                                id: element.id
                            })
                        });
                    }
                } catch (e) {
                    console.log('​catch -> e', e)
                }
            },
            tabChange() {
                let that = this;
                that.$http
                    .get("/app/moral/index", {
                        p: that.p,
                        page: 10,
                        class_id: that.class_id,
                        uid: JSON.parse(Cookies.get('user_71ydj')).id,
                    })
                    .then(res => {
                        if (res.data.moral_index.length) {
                            // that.info = res.data.moral_index
                            console.log(res.data.moral_index)
                            that.info.push(...res.data.moral_index);
                        }
                        this.loadOver = false;
                        if (this.p != 1) {
                            console.log(res.data);
                            if (res.data.moral_index.length) {
                            } else {
                                this.loadOver = true;
                                this.loading = false;
                                this.loaded = '没有更多数据了'
                                return false
                            }
                        } else {
                            if (!res.data.moral_index.length) {
                                this.notMore = true;
                                this.loadOver = false;
                            } else {
                                if (res.data.moral_index.length < 7 && res.data.moral_index.length != 0) {
                                    this.loadOver = true;
                                    this.loaded = '没有更多数据了';
                                    this.notMore =false;
                                }
                            }
                        }
                        // if (res.data.moral_index instanceof Array == false) {
                        // 	that.loaded = "没有更多";
                        // 	that.notMore = false;
                        // 	return;
                        // }
                        // that.info = res.data.moral_index;
                        // if (res.data.moral_index.length < 10) {
                        // 	that.loaded = "没有更多了";
                        // 	that.notMore = false;
                        // 	return;
                        // }
                    });
            },
            toggle(item) {
                item.toggle = !item.toggle;
                if (item.toggle) {
                    item.toggleName = "收起";
                    return;
                }
                item.toggleName = "展开";
            },
            load() {
                if (!this.loadOver) {
                    this.loading = true;
                    clearTimeout(this.method);
                    this.method = setTimeout(() => {
                        this.p = this.p + 1;
                        this.loading = false;
                        // this.initData(this.p,this.status);
                        this.tabChange(this.p)
                    }, 2000);
                }
                //因为load 触发多次 所以做分时节流
                // if (this.notMore) {
                // 	clearTimeout(this.method);
                // 	this.method = setTimeout(() => {
                // 		this.p = this.p + 1;
                // 		this.tabChange();
                // 	}, 500);
                // }
            },

            handleChange(item, index) {
                console.log(item.org_type)
                this.p = 1;
                this.class_id = item.org_type;
                this.loadOver = false;
                this.loading = false;
                this.info = [];
                this.loaded = "加载更多...";
                this.notMore = false;
                this.tabChange();
            }

        },
        created() {
            this.getList()
        }
    }
</script>
<style scoped lang="scss">
    .party_affairs_open_page{
        overflow: hidden;
    }
    /deep/ .ly-tab-active-bar {
        background: -webkit-linear-gradient(left, #eb4e44, #f47447);
        background: -o-linear-gradient(right, #eb4e44, #f47447);
        background: -moz-linear-gradient(right, #eb4e44, #f47447);
        background: linear-gradient(to right, #eb4e44, #f47447);
        border-radius: 10px;
    }

    .note {
        padding: 38px 15px 15px 15px;
        box-sizing: border-box;
        width: 100%;
        position: relative;
    }

    .inform {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-top: 25px;
        span {
            font-size: 28px;
            color: #000;
            font-weight: bold;
        }
    }

    .tabs {
        display: flex;
        justify-content: flex-start;
        width: auto;
        margin-left: -15px;
        element.style {
            background-color: red !important;
        }
    }

    .list {
        width: 100%;
        padding: 15px 15px;
        box-sizing: border-box;
        /*position: absolute;*/
        .bar {
            width: 100%;
            height: 90px;
            box-shadow: -3px 4px 20px #f1f1f1;
            padding: 12px 15px;
            box-sizing: border-box;
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 15px;
            &:last-child {
                margin-bottom: 0;
            }
            .lf {
                width: 93%;
                height: 100%;
                display: flex;
                flex-direction: column;
                .title {
                    width: 100%;
                    p {
                        font-size: 14px;
                        color: #333;
                        margin: 0;
                        padding: 0;
                        display: -webkit-box;
                        -webkit-box-orient: vertical;
                        -webkit-line-clamp: 2;
                        overflow: hidden;
                    }
                }
                .time {
                    font-size: 14px;
                    color: #999;
                    padding: 0;
                    margin-top: 7px;
                }
            }
            .rf img {
                width: 8px;
                height: 13.5px;
            }
        }

    }
    .loading {
        width: 343px;
        margin: 0 16px;
        font-size: 14px;
        color: #dddddd;
        clear: both;
        line-height: 61px;
        text-align: center;
        &.notPageOne {
            margin-top: -40px;
        }
    }
    /*.party_affairs_open_page /deep/ .mu-infinite-scroll{*/
        /*display: none;*/
        /*height: 0;*/
    /*}*/
</style>
<style scoped lang="scss">
    div .mu-tabs {
        position: relative;
        z-index: 97;
        height: 40px;
        margin-bottom: 15px;
        background: none !important;
        margin-top: 40px;
    }

    div .mu-tab-link-highlight {
        width: 16px !important;
        height: 4px !important;
        background: rgba(244, 117, 72, 1);
        border-radius: 2px;
        margin-left: 28px;
    }

    div .mu-tab {
        font-size: 14px;
        font-family: PingFang-SC-Medium;
        font-weight: 500;
        color: #333;
    }

    div .mu-tab-active {
        font-size: 18px;
        font-family: PingFang-SC-Medium;
        font-weight: bold;
        color: #333;
    }

    .empty-text-wrap {
        width: 100%;
        height: 40vh;
        margin-top: 20vh;
    }
    .mu-load-more /deep/ .mu-circle-spinner{
        border-color: #e5e5e5;
    }
    .party_affairs_open_page /deep/.mu-elevation-1{
        box-shadow: 0 0.05333rem 0.02667rem -0.02667rem rgba(0,0,0,0), 0 0.02667rem 0.02667rem 0 rgba(0,0,0,0), 0 0.02667rem 0.08rem 0 rgba(0,0,0,0); ;
        -webkit-box-shadow:0 0.05333rem 0.02667rem -0.02667rem rgba(0,0,0,0), 0 0.02667rem 0.02667rem 0 rgba(0,0,0,0), 0 0.02667rem 0.08rem 0 rgba(0,0,0,0); ;
    }
</style>
